package com.gimi.cloud.jimi.app.consumer.service.user.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;
import com.gimi.cloud.jimi.common.utils.EntityVerification;
import com.gimi.cloud.jimi.common.utils.NumberUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.jimi.app.consumer.feign.UserInfoFeignService;
import com.gimi.cloud.jimi.app.consumer.service.user.UserExpressService;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.userInfo.RdExpressInfoDTO;
/**
 * 配送信息管理
 * @author chendi
 * @date 2017年12月29日
 */
@Service
public class UserExpressServiceImpl implements UserExpressService {
	
	private static Logger logger = LoggerFactory.getLogger(UserExpressServiceImpl.class);
	
    @Autowired
    private UserInfoFeignService userInfoFeignService;
    
	@Override
	public void userExpressAddOrUpdate(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		Integer userId = NumberUtil.getInt(request.getHeader("userId"));
		RdExpressInfoDTO dto = JsonUtil.jsonToBean(requestBody,RdExpressInfoDTO.class);
		dto.setUserId(userId);
		EntityVerification.checkByGroupsThrowsException(dto,RdExpressInfoDTO.AddExpress.class);
        Util.sendResponse(userInfoFeignService.userExpressAddOrUpdate(dto), response);
	}

	@Override
	public void getExpressInfoSingle(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		Integer userId = NumberUtil.getInt(request.getHeader("userId"));
		if(userId == null || userId.equals(0)){
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"userId不能为空");
		}
		//RdExpressInfoDTO dto = JsonUtil.jsonToBean(requestBody,RdExpressInfoDTO.class);
		RdExpressInfoDTO dto = new RdExpressInfoDTO();
		dto.setUserId(userId);
        Util.sendResponse(userInfoFeignService.getExpressInfoSingle(dto), response);
	}

	/*@Override
	public void updateExpressInfo(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		RdExpressInfoDTO dto = JsonUtil.jsonToBean(requestBody,RdExpressInfoDTO.class);
		Util.sendResponse(userInfoFeignService.updateExpressInfo(dto), response);
		
	}*/

	/*@Override
	public void ExpressPageListByUser(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		RdExpressInfoDTO dto = JsonUtil.jsonToBean(requestBody,RdExpressInfoDTO.class);
		Util.sendResponse(userInfoFeignService.ExpressPageListByUser(dto), response);
	}*/

}
